#include <stdio.h>
#include <stdlib.h>

#include "plugin.h"

typedef struct {
    int i;
} echo_cfg_t;

typedef struct {
    echo_cfg_t *cfg;
    int i;
} echo_t;

void *plugin_echo_load(const char *cfg_path) {
    echo_cfg_t *echo_cfg = (echo_cfg_t *)malloc(sizeof(echo_cfg_t));
    printf("[ plugin_echo_load ] cfg path: %s, cfg: %p\n", cfg_path, echo_cfg);
    return echo_cfg;
}

void *plugin_echo_new(void *echo_cfg, const char *param) {
    echo_t *echo = (echo_t *)malloc(sizeof(echo_cfg_t));
    echo->cfg = echo_cfg;
    printf("[ plugin_echo_new ] echo: %p, cfg: %p, param: %s\n", echo, echo_cfg, param);

    return echo;
}

int plugin_echo_process(void *echo, char *fmt, ...) {
    va_list ap;
    va_start(ap, fmt);

    printf("[ plugin_echo_process ] echo: %p >>>>>>>>>>>\n", echo);

    vfprintf(stderr, fmt, ap);
    va_end(ap);

    printf("[ plugin_echo_process ] echo: %p, END <<<<<<<<<<<\n", echo);

    return 0;
}

void plugin_echo_delete(void *echo) {
    printf("[ plugin_echo_delete ] echo: %p\n", echo);
    free(echo);
    echo = NULL;
}

void plugin_echo_unload(void *echo_cfg) {
    printf("[ plugin_echo_unload ] cfg: %p\n", echo_cfg);
    free(echo_cfg);
    echo_cfg = NULL;
}

plugin __g_aiops_plugin_echo = {
    .name    = "echo",
    .load    = plugin_echo_load,
    .new     = plugin_echo_new,
    .process = plugin_echo_process,
    .delete  = plugin_echo_delete,
    .unload  = plugin_echo_unload
};
